﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views {
    import flash.events.*;
    import org.robotlegs.core.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.components.mainmenu.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.fountain.*;
    import net.wooga.pets.models.world.*;

    public class InventoryMediator extends Mediator implements IMediator {

		[Inject]
        public var inventory:InventoryDisplay;
		[Inject]
        public var tutorialModel:TutorialModel;
		[Inject]
        public var languageModel:LanguageModel;
		[Inject]
        public var userModel:UserModel;
		[Inject]
        public var symbolsModel:SymbolModel;
		[Inject]
        public var sessionModel:SessionModel;
		[Inject]
        public var worldModel:WorldModel;

        override public function onRegister():void{
            eventMap.mapListener(eventDispatcher, EventConstants.ENABLED_INVENTORY, this.enabledInventory);
            eventMap.mapListener(eventDispatcher, EventConstants.DISABLED_INVENTORY, this.disabled);
            eventMap.mapListener(eventDispatcher, EventConstants.ON_START_DRAGGING_CUSTOMIZE_ITEM, this.onStartDraggingCustomizeItem);
            eventMap.mapListener(eventDispatcher, EventConstants.ON_STOP_DRAGGING_CUSTOMIZE_ITEM, this.onStopDraggingCustomizeItem);
            eventMap.mapListener(eventDispatcher, EventConstants.ON_STOP_DRAGGING_CUSTOMIZE_ITEM, this.onStopDraggingCustomizeItem);
            eventMap.mapListener(eventDispatcher, GameEvent.TUTORIAL_STATE_CHANGE, this.tutorialStateChange);
            eventMap.mapListener(eventDispatcher, UserModelEvent.ON_MODEL_CHANGED, this.onUserModelChanged);
            eventMap.mapListener(eventDispatcher, EventConstants.SHOW_INVENTORY_GEMS, this.inventoryShowGems);
            eventMap.mapListener(eventDispatcher, EventConstants.UPDATE_SYMBOLS, this.updateSymbols);
            eventMap.mapListener(eventDispatcher, EventConstants.KIOSK_AVAILABLE, this.kioskAvailable);
            eventMap.mapListener(this.inventory, InventoryDisplay.GEM_CLICK, this.gem_click);
            addContextListener(ProtocolConstants.POW_PUBLISH, this.onPostOnWallResult, InfoEvent);
            addContextListener(ProtocolConstants.POW_CANCEL, this.onPostOnWallResult, InfoEvent);
            addContextListener(EventConstants.UPDATE_ASK_FOR_GIFT_BUTTON, this.onUpdateAskForGiftButton, InfoEvent);
            this.onUserModelChanged();
            this.updateSymbols();
            this.setGemsVisibleState();
            this.inventory.showItemByType(GameConstants.BATTERY);
            this.inventory.setTooltipByType(GameConstants.FIRE, this.languageModel.getTextByKey("global_button_ask"));
            this.inventory.setTooltipByType(GameConstants.AIR, this.languageModel.getTextByKey("global_button_ask"));
            this.inventory.setTooltipByType(GameConstants.LOVE, this.languageModel.getTextByKey("global_button_ask"));
            this.inventory.setTooltipByType(GameConstants.STAR, this.languageModel.getTextByKey("global_button_ask"));
            this.inventory.setTooltipByType(GameConstants.WATER, this.languageModel.getTextByKey("global_button_ask"));
            this.inventory.setTooltipByType(GameConstants.ICE, this.languageModel.getTextByKey("global_button_ask"));
            this.kioskAvailable();
        }
        private function inventoryShowGems(_arg1:Event):void{
            this.inventory.showGems();
        }
        private function disabled(_arg1:Event):void{
            this.inventory.mouseEnabled = (this.inventory.mouseChildren = false);
        }
        private function enabledInventory(_arg1:Event):void{
            this.inventory.mouseEnabled = (this.inventory.mouseChildren = true);
        }
        private function gem_click(_arg1:InfoEvent):void{
            var _local2:InfoEvent = new InfoEvent(GameConstants.ASK_FOR_SYMBOL, String(_arg1.id));
            dispatch(_local2);
        }
        private function onUpdateAskForGiftButton(_arg1:InfoEvent):void{
            var _local2:String = _arg1.info.type;
            this.handleRequestLimits(_local2);
        }
        private function onPostOnWallResult(_arg1:InfoEvent):void{
            var _local5:String;
            var _local2:Array = (_arg1.info as Array);
            var _local3:Object = _local2[0];
            var _local4:String = _local3.feed_type;
            if ((((_arg1.type == ProtocolConstants.POW_PUBLISH)) && ((_local4 == GameConstants.ASK_FOR_SYMBOL)))){
                _local5 = _local3.optional_type;
                this.handleRequestLimits(_local5);
            };
        }
        private function handleRequestLimits(_arg1:String):void{
            this.sessionModel.setRequestLimit(_arg1, true);
            this.inventory.setGemEnabled(_arg1, false);
        }
        private function kioskAvailable(_arg1:Event=null):void{
            var _local2:Boolean = this.worldModel.hasAreaType(GameConstants.KIOSK);
            ((_local2) && (this.inventory.showItemByType(GameConstants.COFFEE)));
        }
        private function updateSymbols(_arg1:InfoEvent=null):void{
            var _local3:String;
            var _local2:Object = this.symbolsModel.symbols;
            for (_local3 in _local2) {
                this.inventory.setNumberByType(_local3, int(_local2[_local3]));
                this.inventory.setGemEnabled(_local3, !(this.sessionModel.getRequestLimit(_local3)));
            };
            InventoryDisplay.FIRST_TIME_DATA_SET = false;
        }
        private function setGemsVisibleState():void{
            if (this.userModel.level >= 5){
                this.inventory.showGems();
            };
        }
        private function tutorialStateChange(_arg1:GameEvent):void{
            var _local2 = (this.tutorialModel.state == TutorialModel.LEVEL1_BATTERY_TO_TREATMENT);
            if (_local2){
                this.inventory.highlightSlot(GameConstants.BATTERY);
            };
        }
        private function onUserModelChanged(_arg1:Event=null):void{
            this.inventory.setNumberByType(GameConstants.BATTERY, this.userModel.batteries);
            this.inventory.setNumberByType(GameConstants.COFFEE, this.userModel.coffee);
        }
        private function onStartDraggingCustomizeItem(_arg1:Event):void{
            this.inventory.setEnabled(false);
        }
        private function onStopDraggingCustomizeItem(_arg1:Event):void{
            this.inventory.setEnabled(true);
        }

    }
}//package net.wooga.pets.views 
